import java.util.Arrays;

//https://leetcode.cn/problems/fibonacci-number/
class Solution {
    //记忆化搜索
    int[] memo;//memory
    public int fib(int n) {
        memo = new int[31];
        Arrays.fill(memo, -1);//不可能出现的数
        return dfs(n);
    }
    public int dfs(int n) {
        if(memo[n] != -1) return memo[n];
        if(n == 0 || n == 1) {
            memo[n] = n;
            return n;
        }
        memo[n] = dfs(n - 1) + dfs(n - 2);
        return memo[n];
    }
}